//
//  ViewController.m
//  City
//
//  Created by student on 16/3/3.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSArray *states;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *path = [[NSBundle mainBundle] pathForResource:@"area1" ofType:@"plist"];
    self.states = [NSArray arrayWithContentsOfFile:path];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.states.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *arr=[[NSArray alloc]init];
    arr = self.states[section][@"Cities"];
    return arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    NSArray *arr=[[NSArray alloc]init];
    arr = self.states[indexPath.section][@"Cities"];
    cell.textLabel.text = arr[indexPath.row][@"city"];
    return cell;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *arr=[[NSString alloc]init];
    arr=self.states[section][@"State"];
    return  arr;
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    NSMutableArray *arr=[[NSMutableArray alloc]init];
    for(int i=0;i<self.states.count;i++)
    {
        [arr addObject:self.states[i][@"State"]];
    }
    return arr;
}

@end
